import Axios from 'axios';
const myaxios = {}

//获取本地储存的token
// const token = JSON.parse(localStorage.getItem('userinfo')).token

myaxios.install = function (Vue) {
    // Vue.prototype.$myreq = function () {
    //     console.log('vue--user 能用');
    //   }
    //将默认的axios 实例对象挂载到vue 插件
    // Vue.prototype.$axios = Axios

    //将自定义的axios 实例对象挂载到vue 插件
    const myAxiosObj = Axios.create({
        baseURL: 'http://localhost:8888/api/private/v1',
        // headers: { 'Authorization': token }
    })
    //拦截器
    myAxiosObj.interceptors.request.use(function (config) {
        if (config.url !== '/login') {
            //登录之后才能获取token
            const token = JSON.parse(localStorage.getItem('userinfo')).token
            config.headers.Authorization = token
        }
        // console.log(config);
        return config
    })
    Vue.prototype.$axios = myAxiosObj
}
export default myaxios